package com.play.ballen.synthetic.adapter

import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.play.ballen.R
import com.play.ballen.synthetic.entity.Guess
import com.play.ballen.synthetic.entity.SyntheticBallInfo
import com.yuven.appframework.util.imageloader.ImageUtil
import com.yuven.baselib.utils.ResourceUtil

class SyntheticBallAdapter(data: MutableList<Guess>) :
    BaseQuickAdapter<Guess, BaseViewHolder>(R.layout.item_synthetic_ball, data) {


    init {
        addChildClickViewIds(R.id.btnDoGuess,R.id.btn_hecheng)
    }


    override fun convert(holder: BaseViewHolder, item: Guess) {

        val imgBall = holder.getView<ImageView>(R.id.imgBall)
        val tvPropertyLevel = holder.getView<TextView>(R.id.tvPropertyLevel)
        val tvPropertySport = holder.getView<TextView>(R.id.tvPropertySport)
        val tvPropertyDate = holder.getView<TextView>(R.id.tvPropertyDate)
        val tvPropertyPlayCount = holder.getView<TextView>(R.id.tvPropertyPlayCount)
        val tvPropertyLeftCount = holder.getView<TextView>(R.id.tvPropertyLeftCount)
        val tvSyntheticCount = holder.getView<TextView>(R.id.tvSyntheticCount)
        val btnDoGuess = holder.getView<TextView>(R.id.btnDoGuess)
        val btn_hecheng = holder.getView<TextView>(R.id.btn_hecheng)

        item.run {
            ImageUtil.instance.loadImage(0, 0, item.basketball.pic, imgBall)

            tvPropertyLevel.text = item.basketball.name
            tvPropertyPlayCount.text =
                ResourceUtil.getString(R.string.home_property_play_count_text, item.basketball.task_count)
            tvPropertyDate.text = if (item.basketball.name != "0") {
                ResourceUtil.getString(R.string.home_property_date_forever)
            } else {
                ResourceUtil.getString(R.string.twenty_end)
            }

            tvPropertySport.text = "${item.basketball.percent}%"

            tvPropertyLeftCount.text = item.basketball.remain.toString()
            tvSyntheticCount.text = item.basketball.grouped.toString()

            if(item.today_join_num==0){
                btnDoGuess.text = ResourceUtil.getString(R.string.synthetic_guess_ok)
                btnDoGuess.setBackgroundResource(R.drawable.layer_orange_shadow_button)
                btnDoGuess.isEnabled = true
            }else{
                btnDoGuess.text = ResourceUtil.getString(R.string.synthetic_guess_end)
                btnDoGuess.isEnabled = false
                btnDoGuess.setBackgroundResource(R.drawable.layer_grey_shadow_button)
            }

            if(item.combo_num>0){
                btn_hecheng.text = ResourceUtil.getString(R.string.synthetic_guess_combo)
                btn_hecheng.setBackgroundResource(R.drawable.layer_orange_shadow_button)
                btn_hecheng.isEnabled = true
            }else{
                btn_hecheng.text = ResourceUtil.getString(R.string.synthetic_guess_combo_1)
                btn_hecheng.setBackgroundResource(R.drawable.layer_grey_shadow_button)
                btn_hecheng.isEnabled = false
            }

        }
    }

}